﻿using DevExpress.XtraEditors;
using System;
using XCI.Core;

namespace XCI.Extensions
{
    public static class DateEditExtensions
    {
        public static void ConfigDate(this TextEdit edit, Action<TextEdit> action = null)
        {
            var formatString = R.DEFAULT_DATE_PATTERN;
            edit.Properties.DisplayFormat.FormatString = formatString;
            edit.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.EditFormat.FormatString = formatString;
            edit.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.Mask.EditMask = formatString;
            action?.Invoke(edit);
        }

        public static void ConfigDateTime(this TextEdit edit, Action<TextEdit> action = null)
        {
            var formatString = R.DEFAULT_DATETIME_PATTERN;
            edit.Properties.DisplayFormat.FormatString = formatString;
            edit.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.EditFormat.FormatString = formatString;
            edit.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.Mask.EditMask = formatString;

            action?.Invoke(edit);
        }

        public static void ConfigDate(this DateEdit edit, Action<DateEdit> action = null)
        {
            var formatString = R.DEFAULT_DATE_PATTERN;
            edit.Properties.DisplayFormat.FormatString = formatString;
            edit.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.EditFormat.FormatString = formatString;
            edit.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.Mask.EditMask = formatString;
            action?.Invoke(edit);
        }

        public static void ConfigDateTime(this DateEdit edit, Action<DateEdit> action = null)
        {
            var formatString = R.DEFAULT_DATETIME_PATTERN;
            edit.Properties.DisplayFormat.FormatString = formatString;
            edit.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.EditFormat.FormatString = formatString;
            edit.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            edit.Properties.Mask.EditMask = formatString;

            action?.Invoke(edit);
        }
    }
}